﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TS_XY_Train_Repaire.UserCon.Locomotive
{
    public partial class uc_PlaneKouche : DevExpress.XtraEditors.XtraForm
    {
        public uc_PlaneKouche()
        {
            InitializeComponent();
        }
        public string f_mainid = "";
        public string f_id = "";
        private void uc_PlaneKouche_Load(object sender, EventArgs e)
        {
            TS_Win_Class.FillListTypeAct(cbjx, "select * from TS_S_T_P_TrainType where f_del=0");
            TS_Win_Class.FillListTypeAct(cbcx, "select * from TS_S_T_P_RailwayStations where f_del=0");
            TS_Win_Class.FillListTypeAct(cbps, "select * from TS_S_T_P_RailwayStations where f_del=0");
            TS_Win_Class.FillListTypeAct(cbxc, "select * from TS_S_T_P_Train_RP where f_del=0");
            
            if (f_id != "") {
                string sql = "select * from TS_TR_PS_Loco_Repair_Plane_Train where f_id=" + f_id;
                DataTable dt = TS_Win_Class.GetFilledDataTable(sql);
                cbjx.SelectedValue = dt.Rows[0]["f_ttid"];
                cbxc.SelectedValue = dt.Rows[0]["f_rpid"];
                cbch.SelectedValue = dt.Rows[0]["f_trainid"];
                cbps.SelectedValue = dt.Rows[0]["f_arsid"];
                cbcx.SelectedValue = dt.Rows[0]["f_rrsid"];
                tbjx.Text = dt.Rows[0]["f_monthname"].ToString();
                tbbrief.Text = dt.Rows[0]["f_brief"].ToString();
            }
            
        }

        private void cbjx_SelectedIndexChanged(object sender, EventArgs e)
        {
            TS_Win_Class.FillListTypeAct(cbch, "select * from TS_S_T_P_Train_List where f_del=0 and f_ttid=" + cbjx.SelectedValue);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (f_id != "") 
            {
                string sql = @"update TS_TR_PS_Loco_Repair_Plane_Train set f_trainid="+cbch.SelectedValue+",f_name='"+cbch.Text+"',f_ttid="+cbjx.SelectedValue+",f_ttname='"+cbjx.Text+"',f_rrsid="+cbcx.SelectedValue+",f_rrsname='"+cbcx.Text+"',f_arsid="+cbps.SelectedValue+",f_arsname='"+cbps.Text+"',f_rpid="+cbxc.SelectedValue+",f_rpname='"+cbxc.Text+"',f_monthname='"+tbjx.Text+"',f_stime='"+dpt1.Value+"',f_etime='"+dpt2.Value+"',f_ltime='"+dpt3.Value+"',f_brief='"+tbbrief.Text.Trim()+"' where f_id="+f_id;
                TS_Win_Class.MySqlCom(sql);
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                string sql = @"insert into TS_TR_PS_Loco_Repair_Plane_Train (f_mainid,
f_trainid,
f_name,
f_ttid,
f_ttname,
f_rrsid,
f_rrsname,
f_arsid,
f_arsname,
f_rpid,
f_rpname,
f_monthname,
f_stime,
f_etime,
f_ltime,
f_brief,
f_state,
f_workerid
) values(" + f_mainid + "," + cbch.SelectedValue + ",'" + cbch.Text + "'," + cbjx.SelectedValue + ",'" + cbjx.Text + "'," + cbcx.SelectedValue + ",'" + cbcx.Text + "'," + cbps.SelectedValue + ",'" + cbps.Text + "'," + cbxc.SelectedValue + ",'" + cbxc.Text + "','" + tbjx.Text + "','" + dpt1.Value + "','" + dpt2.Value + "','" + dpt3.Value + "','"+tbbrief.Text.Trim()+"',0," + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ")";
                TS_Win_Class.MySqlCom(sql);
                this.DialogResult = DialogResult.OK;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
